%{'SPD','CDU','CSU','Green','FDP','PDS'}
xMani98   =[-1.603 24.868 NaN -16.256  14.704 -26.816 ];
sel98=not(isnan(xMani98));

%{'SPD','CDU','CSU','Green','FDP','LP','Rep','SP'}
xMani02   =[4.099  20.76  NaN -13.434 4.591 -21.327 NaN NaN];
sel02=not(isnan(xMani02));

%{'SPD','CDU','FDP','LP','Green','CSU','NPD'}
xMani05   =[-2.154 25.611  16.913 -31.239 -10.445 NaN NaN];
sel05=not(isnan(xMani05));

%{'CDU','SPD','FDP','LP','Green','CSU'}
xMani09   =[ 8.724 -18.297  4.272 -24.519 -13.571 NaN];
sel09=not(isnan(xMani09));

%{'CDU','SPD','LP','Green','CSU','FDP','AFD','Pirates'}
xMani13=[ 2.564 -23.568 -34.547 -19.595 NaN 14.036 -2.74 -12.653];                                  
sel13=not(isnan(xMani13));

%{'CDU','SPD','AFD','FDP','LP','Green','CSU'}
xMani17=[2.757 -21.437 17.43 0.578 -41.914 -21.058 NaN];
sel17=not(isnan(xMani17));


D=GERN.M98;
sel=not(isnan(sum(D(:,sel98),2)));
D98=D(sel,sel98);
ManiTests.P98=sum(sel98);
ManiTests.N98=sum(sel);


D=GERN.Ma02;
sel=not(isnan(sum(D(:,sel02),2)));
D02=D(sel,sel02);
ManiTests.P02=sum(sel02);
ManiTests.N02=sum(sel);


D=GERN.M05;
sel=not(isnan(sum(D(:,sel05),2)));
D05=D(sel,sel05);
ManiTests.P05=sum(sel05);
ManiTests.N05=sum(sel);

D=GERN.M09;
sel=not(isnan(sum(D(:,sel09),2)));
D09=D(sel,sel09);
ManiTests.P09=sum(sel09);
ManiTests.N09=sum(sel);

D=GERN.M13;
sel=not(isnan(sum(D(:,sel13),2)));
D13=D(sel,sel13);
ManiTests.P13=sum(sel13);
ManiTests.N13=sum(sel);

D=GERN.M17;
sel=not(isnan(sum(D(:,sel17),2)));
D17=D(sel,sel17);
ManiTests.P17=sum(sel17);
ManiTests.N17=sum(sel);

filedir=pwd;

sdir=strcat(filedir,'/TESTRESULTS/');
cdir=strcat(filedir,'/TwoStepMatlab/');
addpath(cdir)

for version=1:3
    if version == 2
        warning('off','MATLAB:nearlySingularMatrix')
    else
        warning('on','MATLAB:nearlySingularMatrix')
    end
    [WM,order]=CMoment(D98,xMani98(sel98));
    [ManiTests.rej98,ManiTests.s98,ManiTests.crVa98,ManiTests.muNu98] = ModTestTwoStep(-WM,0.05,version,10000);

    [WM,order]=CMoment(D02,xMani02(sel02));
    [ManiTests.rej02,ManiTests.s02,ManiTests.crVa02,ManiTests.muNu02] = ModTestTwoStep(-WM,0.05,version,10000);
    
    [WM,order]=CMoment(D05,xMani05(sel05));
    [ManiTests.rej05,ManiTests.s05,ManiTests.crVa05,ManiTests.muNu05] = ModTestTwoStep(-WM,0.05,version,10000);
    
    [WM,order]=CMoment(D09,xMani09(sel09));
    [ManiTests.rej09,ManiTests.s09,ManiTests.crVa09,ManiTests.muNu09] = ModTestTwoStep(-WM,0.05,version,10000);
    
    [WM,order]=CMoment(D13,xMani13(sel13));
    [ManiTests.rej13,ManiTests.s13,ManiTests.crVa13,ManiTests.muNu13] = ModTestTwoStep(-WM,0.05,version,10000);
    
    [WM,order]=CMoment(D17,xMani17(sel17));
    [ManiTests.rej17,ManiTests.s17,ManiTests.crVa17,ManiTests.muNu17] = ModTestTwoStep(-WM,0.05,version,10000);
    
    file=strcat('ManiTests',int2str(version));
    file=strcat(sdir,file);
    save(file,'ManiTests')
end